//
// Created by bleedingfight on 2020/6/28.
//
#include "duplicate.h"

int duplicate(std::vector<int>& nums) {
<<<<<<< HEAD:cxx/algorithm/src/duplicate.cc
    int length = nums.size();
    for (int i = 0; i < length; i++) {
        while (nums[i] != i) {
            if(nums[i]==nums[nums[i]])
                return nums[i];
            std::swap(nums[i], nums[nums[i]]);
        }
    }
    return -1;
=======
  int length = nums.size();
  for (int i = 0; i < length; i++) {
    while (nums[i] != i) {
      if (nums[i] == nums[nums[i]]) return nums[i];
      std::swap(nums[i], nums[nums[i]]);
    }
  }
  return -1;
>>>>>>> dev:cxx/algorithm/common/src/duplicate.cc
}
